import { BUNDLE_TYPE_ENUM, EVENT_NAME_ENUM } from "../base/EnumIndex";
import { ActionTools } from "../common/ActionTools";
import { EventManager } from "../manager/EventManager";
import { ResManager1 } from "../manager/ResManager1";

const { ccclass, property } = cc._decorator;

/**
 * 游戏目标  当前时速：0 km/h
 */
@ccclass
export default class GoalItem extends cc.Component {

    @property(cc.Sprite)
    spr: cc.Sprite = null;
    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.Label)
    unit: cc.Label = null;

    @property(cc.Label)
    num: cc.Label = null;
    onLoad() {
        EventManager.ins.on(EVENT_NAME_ENUM.UPDATE_GOAL, this.updateGoalNum, this);
    }
    onDestroy() {
        EventManager.ins.off(EVENT_NAME_ENUM.UPDATE_GOAL, this.updateGoalNum, this);
    }
    async initTitleSpr(sprUrl: string) {
        this.spr.spriteFrame = await ResManager1.ins.loadRes(sprUrl, cc.SpriteFrame, BUNDLE_TYPE_ENUM.LEVEL);
    }

    initTitleLabel(title: string) {
        this.title.node.active = true;
        this.spr.node.active = false;
        this.title.string = title;
    }

    initUnit(unit: string) {
        this.unit.string = unit;
    }

    updateGoalNum(num: number) {
        ActionTools._ins.gunNumLabAni(this.num, num);
        // this.num.string = num.toString();
    }

    // update (dt) {}
}
